home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 49 / Amiga Format CD49 (2000-01-17)(Future Publishing)(GB)(Track 1 of 3)[!][issue 2000-02].iso / -serious- / programming / basic / onlinetimer / onlinetimer.text < prev    next >
Text File  |  1999-12-06  |  3KB  |  70 lines

  1. Short:    Timer for serial port Carrier Detection
  2. Author:   simon@studio.woden.com (Simon N Goodwin)
  3. Uploader: simon@studio.woden.com (Simon N Goodwin)
  4. Version:  1.3
  5. Type:     dev/basic
  6.  
  7.  
  8. OVERVIEW
  9.  
  10. This simple HiSoft BASIC program from my Amiga Format series 'Banging
  11. The Metal' shows a low-level way to record time spent online, for
  12. communication software like TERM as well as TCP/IP stacks. It works
  13. by reading the standard serial port hardware. Similar hacks are
  14. possible for other interfaces, if you know their port addresses.
  15.  
  16. There are two versions - the simple one counts in seconds, while the
  17. other counts in traditional Babylonian hours, minutes and seconds ;-)
  18.  
  19.  
  20. CAVEATS
  21.  
  22. Both get confused by signed arithmetic at midnight. They are bare-bones
  23. examples and intended to show how low-level information can be obtained,
  24. not what to do with it, or when it might be useful: typically only on
  25. your own system, for your own purposes - metal bashing is otherwise
  26. rightly disparaged because it leads to unrepresentative and incompatible
  27. software.
  28.  
  29.  
  30. OPERATION
  31.  
  32. The example directly reads a bit in port A on CIAB, so it suits all real
  33. Amigas and accurate emulations - but not clones like Draco that lack CIAs.
  34. Signals are generally 'active low' - so a 0 level on bit 5 of CIAB port A
  35. indicates modem carrier detection, for instance. In assembler you'd write:
  36.  
  37.     btst    #5,$BFD000
  38.     bne    NoCarrier
  39.  
  40. The BASIC equivalent is:
  41.  
  42.     IF PEEK(12570624) AND 32 THEN PRINT "No Carrier"
  43.  
  44. The example is an elaborated version of this test. Notice that it does
  45. NOT busy-wait - the WAIT command ensures that the majority of CPU time
  46. is made available to other tasks and processes. Hardware PEEKs need not
  47. be system-hostile!
  48.  
  49.  
  50. HISTORY
  51.  
  52. Originally written by Simon N Goodwin (simon@silicon.studio.co.uk) for the
  53. Amiga Format Banging The Metal tutorial, first published May 1999. Aminet
  54. release by mutual agreement of the author and first publisher. No exclusive
  55. rights relate to this example. It may be freely copied only in its entirety.
  56.  
  57.  
  58. DIVERSION
  59.  
  60. When programming the serial or parallel port, utilities like MapDevice may
  61. divert calls  for SER: or PRT: to alternative hardware. Opening the standard
  62. name doesn't necessarily allocate the default hardware. Check this with
  63. another PEEK, using the eponymous command from Aminet/util/cli/PEEK_POKE.lha
  64.  
  65.     PEEK DEV=serial long 10 string
  66.  
  67. This returns the name of the /real/ device selected when you open the device
  68. named after DEV= above, such as "pit.device".for Multiface parallel
  69. redirection, or "duart.device" for GVP serial ports.
  70.